function f_exe_ssh_comm()
{ #执行ssh命令, 如果ssh_type=ssh就会用ssh去执行, 如果是msrt就会用msrt去执行, msrt能执行的权限比较大
    declare ssh_host ssh_comm
    ssh_host="${1}"
    ssh_comm="${2}"
    if [ "${ssh_type}x" == "msrtx" ]
    then
        ${msrt} --host ${ssh_host} --comm "${ssh_comm}"
    else
        sudo -u ${ssh_user} ssh ${SSHOPTION} ${ssh_user}@${ssh_host} "${ssh_comm}"
    fi
}

function f_check_ssh_auth()
{
    declare _ssh_host max_edit_ssh edit_ssh fun_name msrt_state
    _ssh_host="${1}"
    fun_name="f_check_ssh_auth"
    [ "${no_check_disk}x" == "falsex" ] && return 0
    if [ "${ssh_type}x" == "msrtx" ]
    then
        msrt_state="$(${msrt} --host ${_ssh_host} --comm "echo test"|grep -c "{\"STATE\":0,\"INFO\":\"OK\"}")"
        if [ "${msrt_state}x" == "0x" ]
        then 
            f_logging "ERROR:${fun_name}" "目标master节点 '${_ssh_host}' 未启用msrt工具或者监听的端口不是${msrt_port}, 请排查, 本次将不检查磁盘空间" "2"
            no_check_disk="false"
            [ "${_ssh_host}x" != "${mysql_host}x" ] && return 1
        fi
        return 0
    fi

    #检查ssh互信, 没有的话就建立互信, 本机跟master节点, 这是一个api创建ssh通道
    max_edit_ssh=3     #最多尝试几次
    for ((edit_ssh=1; edit_ssh<=${max_edit_ssh}; edit_ssh++))
    do
        f_exe_ssh_comm "${_ssh_host}" "exit" >/dev/null 2>&1 && exe_state="${?}" || exe_state="${?}"

        if [ ${exe_state} -ne 0 ] && [ "${edit_ssh}x" == "5x" ]
        then
            f_logging "ERROR:${fun_name}" "目标master节点 '${_ssh_host}' 与本机 '${localhost_ip}' 没用做ssh互信, 本次将不检查磁盘空间" "2"
            no_check_disk="false"
        fi
        sleep 1
    done
    return 0
}

